public class ComparessingWords{
  public String compressWords(String str) {
    StringBuffer sb = new StringBuffer();
    int count = 1;
    
    sb.append(str.charAt(0));
    for (int i = 1; i < str.length(); i++) {
      if(str.charAt(i) == str.charAt(i-1)){  
        count++;
        continue;
      }
    if(str.charAt(i) != str.charAt(i-1)) {
      sb.append(count);
      sb.append(str.charAt(i));
      count = 1;
      }
    }
    sb.append(count);

  return sb.toString().length()<= str.length? sb.toString():str;
  }








}